<?php

class Contact extends MY_Controller {

	function Contact()
	{
		parent::MY_Controller();
		$this->load->model('Contact_model');
	}
	

	function index()
	{	
		// Set meta
		$title = $this->data['site']['site_title'];
		$data['web_title'] = $title;
		$data['meta_title'] = $title;
		$data['meta_description'] = purify($this->data['site']['site_description']);
		$data['meta_keyword'] = $this->data['site']['site_keyword'];

		
		// Send and Load page
		$data['page'] = 'contact_view';
		$this->load->vars($data);
		$this->load->view('template_view');	
	}
	
	function dosend()
	{
		$rules =array(
					array(
							'field'=>'name',
							'label'=>'Name',
							'rules'=>'trim|required|xss_clean|max_length[255]'
					),
					array(
							'field'=>'telp',
							'label'=>'Telp',
							'rules'=>'trim|xss_clean|max_length[50]'
					),
					array(
							'field'=>'email',
							'label'=>'Email',
							'rules'=>'trim|required|xss_clean|valid_email|max_length[255]'
					),
					array(
							'field'=>'address',
							'label'=>'address',
							'rules'=>'trim|xss_clean'
					),
					array(
							'field'=>'message',
							'label'=>'Message',
							'rules'=>'trim|required|xss_clean'
					)	
			);	
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');		
		$this->form_validation->set_rules($rules);	
		
		if ($this->form_validation->run()==FALSE)
		{
				echo '<div class="result_error"><h3>Pengiriman Pesan Gagal </h3>Please review some mistake:<br />'.validation_errors().'</div>';
		}
		else
		{
			$status = 'I';
			$ip=$this->input->ip_address();
			$this->Contact_model->insert($status);
			// Send Email
			$this->email->clear();
			$this->email->from('no-reply@slutenamujarab.com', 'Pesan Dari Website');
			$this->email->to('info@slutenamujarab.com, arisofyan.arie@gmail.com');		
			$this->email->subject('[slutenamujarab.com]: Anda mendapat pesan ');	// Edit Judul			
			$message = 'Assalammua`laikum wr. wb.: <br /><br /> ';
			$message .= 'Anda mendapatkan pesan dari : <br /> ';
			$message .= '<b>Nama:</b><br> ' . $this->input->post('name') . '<br />';
			$message .= '<b>Alamat:</b><br> ' . $this->input->post('address') . '<br />';
			$message .= '<b>Email:</b><br> <a href="mailto:'.$this->input->post('email').'">' . $this->input->post('email') . '</a><br />';
			$message .= '<b>Telp:</b><br> ' . $this->input->post('telp') . '<br />';
			$message .= '<b>Pesan:</b><br> ' . $this->input->post('message') . '<br />';
			$message .= '<b>Tanggal dikirim:</b><br>' . date("Y-m-d H:i:s") . '<br />';
			$message .= '<b>IP Address:</b><br>' . $this->input->ip_address() . '<br />';			
			$message .= '<br /><br />Terima Kasih,<br /> slutenamujarab.com team';	
									
			$this->email->message($message);
			$this->email->send();
			$this->email->print_debugger();				
			echo '<div class="result_success"><h3>Terima Kasih, pesan anda akan kami balas secepatnya!</h3></div>';
		}

	}
}	

/* End of file kontak.php */
/* Location: ./application/controllers/Contact.php */
?>